package kr.saeildamil.androidstudty.ch07;

import kr.saeildamil.androidstudty.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

public class DrawBitmapEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);	
		DrawView dv=new DrawView(this);
		setContentView(dv);
	}
}

class DrawView extends View {
	Bitmap bit;
	Bitmap backbit;
	Canvas offscreen;
	Paint Pnt;

	public DrawView(Context context) {
		super(context);
		bit = BitmapFactory.decodeResource(getResources(), R.drawable.harubang);
		backbit = Bitmap.createBitmap(300, 200, Bitmap.Config.ARGB_8888);
		offscreen = new Canvas(backbit);
		offscreen.drawColor(Color.GREEN);
		Pnt = new Paint();
		Pnt.setColor(Color.RED);

	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		/*
		 * canvas.drawBitmap(bit, 10, 10, null);//원본이미지를 (10,10)위치에 드로우
		 * canvas.drawBitmap(bit, null, new Rect(120, 10, 170, 85), null);//이미지
		 * 축소 canvas.drawBitmap(bit, new Rect(30, 30, 70, 80), new Rect(180, 20,
		 * 180+80, 10+100),null); canvas.drawColor(Color.LTGRAY);
		 */
		canvas.drawColor(Color.LTGRAY);
		for (int x = 0; x < 300; x += 10) {
			offscreen.drawLine(x, 0, 300 - x, 200, Pnt);
		}
		canvas.drawBitmap(backbit, 10, 10, null);
	}
}
